home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Shareware / Utilitare / winhex / Sample script.whs < prev    next >
Text File  |  2004-03-04  |  2KB  |  59 lines

  1. // WinHex sample script, demonstrating various script commands.
  2. // Can only be executed by the evaluation version if unchanged.
  3.  
  4. MessageBox "Attention: all windows will now be closed without prompting."
  5. CloseAll
  6.  
  7. // Create a file named "abcdefgh.dat" with 123456 bytes in the root directory of drive C:.
  8. // Will overwrite this file in case it already exists.
  9. Create "C:\abcdefgh.dat" 123456
  10.  
  11. MessageBox "The sample file 'abcdefgh.dat' has been created."
  12.  
  13. // Write some text at offset 0.
  14. Write "This file was created by a WinHex sample script."
  15.  
  16. // Write 16 magic hex values at offset 0x100.
  17. Goto 0x100
  18. Write 0x57696E48657820697320677265617421
  19. Move -16
  20. // Now we are back at offset 0x100.
  21.  
  22. // Open drive C:
  23. Open C:
  24.  
  25. // To find out whether this drive has a FAT file system, search for
  26. // the string "FAT" in the boot sector. Could also be implemented as
  27. // Goto 0x36
  28. // Read "A three-character variable" 3
  29. // IfEqual "A three-character variable" "FAT"
  30.  
  31. Block 0 511
  32. Find "FAT" BlockOnly
  33. IfFound
  34.     // Search for the directory entry "abcdefghdat". This only works on FAT drives.
  35.     MessageBox "Drive C: has a FAT file system. Now looking for the directory entry of 'abcdefgh.dat'."
  36.     Find "abcdefghdat"
  37. Else
  38.     // Search for the filename "abcdefgh.dat" in Unicode, as stored on NTFS drives.
  39.     MessageBox "Drive C: does not have a FAT file system. Now looking for an NTFS entry of 'abcdefgh.dat'."
  40.     Find "abcdefgh.dat" Unicode
  41. EndIf
  42.  
  43. // Now go back to the file.
  44. NextObj
  45. // We know that the only other open window is the file we created,
  46. // since initially all other possibly open windows were closed.
  47.  
  48. // Convert the file from Binary to HexASCII and back 3 times.
  49. {
  50.     Convert Binary HexASCII
  51.     Convert HexASCII Binary
  52. }[3]
  53.  
  54. // Now make drive C: the active window again, to show
  55. // that the directory entry of "abcdefgh.dat" has been
  56. // found.
  57. NextObj
  58.  
  59. MessageBox "Sample script execution complete. The file has been converted a few times, and its directory entry has hopefully been found in the file system."